<template>
  <!-- // 分配角色 -->
  <div>
    <el-checkbox-group v-model="roleIds">
      <el-checkbox v-for="item in rolesList" :key="item.id" :label="item.id">{{
        item.name
      }}</el-checkbox>
    </el-checkbox-group>
    <div style="margin-top: 20px; text-align: right">
      <el-button type="primary" @click="roleHandle">确定</el-button>
      <el-button @click="closeDialog">取消</el-button>
    </div>
  </div>
</template>
<script>
import { getRolesListApi } from '@/api/settings'
import { getUserDetailById } from '@/api/user'
import { assignRoles } from '@/api/employees'
export default {
  props: {
    empId: {
      type: String
    }
  },
  data() {
    return {
      roleIds: [], // 双向绑定,让谁勾选
      paramsObj: {
        page: 1,
        pagesize: 80
      },
      rolesList: []
    }
  },
  created() {
    this.getRoles()
  },
  methods: {
    closeDialog() {
      this.$emit('close')
    },
    async getRoles() {
      const res = await getRolesListApi(this.paramsObj)
      this.rolesList = res.data.rows
      const res2 = await getUserDetailById(this.empId) // 获取当前行信息里的角色权限
      // console.log(res2, 857)
      this.roleIds = res2.data.roleIds
    },
    async roleHandle() {
      await assignRoles({
        id: this.empId,
        roleIds: this.roleIds
      })
      this.closeDialog()
    }
  }
}
</script>
